package com.example.product.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.product.entity.CategoryEntity;
import com.example.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class IndexController {
    
    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/","/index.html"})
    public String indexPage(Model model) {
        // 查出所有的以及分类
        List<CategoryEntity> firstCategory = categoryService
                .list(new QueryWrapper<CategoryEntity>().eq("parent_cid",0));
        model.addAttribute("firstCategory",firstCategory);
        return "index";
    }
}
